<template>
  
    <div ref="whole_cost_id" style="width:100%;" >
      <el-button type="primary" v-on:click="exportSummary" >导 出</el-button>
        <div class="vehicles" >
            
            <table border="1" style="width:100%;" cellpadding="0" cellspacing="0">
                <tr>
                    <td :colspan = 4 >边际测算</td> 
                    <td>{{wholeCostVo.materialnum_name}} </td>
                    <td>备注</td>
                    <td>汇总金额</td>
                </tr>
                <tr>
                  <td :colspan = 4 >物料号</td>
                  <td>{{wholeCostVo.materialnum}} </td>
                  <td></td>
                  <td></td>
                </tr>
                <tr v-for="(rowData, rowIndex) in dataList" :key="rowIndex">
                    <template v-if="rowData.level_state_1==1">
                      <td :rowspan="rowData.level_count_1" > 
                          {{rowData.level_name_1}} 
                      </td>
                    </template>
                    <template v-if="rowData.level_state_2==1">
                      <td :rowspan="rowData.level_count_2" > 
                          {{rowData.level_name_2}} 
                      </td>
                    </template>
                    <template v-if="rowData.level_state_3==1">
                      <td :rowspan="rowData.level_count_3" > 
                          {{rowData.level_name_3}} 
                      </td>
                    </template>
                    <td>{{rowData.describe}}</td>
                    <td>{{rowData.componentnum}}</td>
                    <td>{{rowData.componentnum_name}}</td>
                    <td>{{rowData.amount}}</td>
                </tr>
            </table>
        </div>
    </div>
</template>

<script>
import http from "@/api/http.js";
export default {
components: {
   
  },
  data() {
    var now=new Date();
    return {
      dataList:[],
      wholeCostVo:{},
    };
  },
  created() {
    

  },
  methods: {
    
    exportSummary(){//使用文件流下载文件

      let yjy_whole_info_id = this.$store.getters.data().yjy_whole_info_id;
      let materialnum = this.$store.getters.data().materialnum;
        let url=this.http.ipAddress +
              "api/yjy_whole_cost/exportWholeCostSummary?yjy_whole_info_id="+yjy_whole_info_id+"&materialnum="+materialnum;
        http.post(url, {}, "正在导出数据....", { responseType: "blob" }).then((content) => {
        const blob = new Blob([content]);
            if ("download" in document.createElement("a")) {
              // 非IE下载
              const elink = document.createElement("a");
              elink.download = "整车数据汇总表.xlsx";
              elink.style.display = "none";
              elink.href = URL.createObjectURL(blob);
              document.body.appendChild(elink);
              elink.click();
              URL.revokeObjectURL(elink.href);
              document.body.removeChild(elink);
            }else{
              navigator.msSaveBlob(blob, "导出文件非IE.xlsx");
            }
        })
      },

    },
  computed: {

},
  mounted() {
    let yjy_whole_info_id = this.$store.getters.data().yjy_whole_info_id;
    let materialnum = this.$store.getters.data().materialnum;
    let url = "/api/yjy_whole_cost/getWholeCostListSummary?yjy_whole_info_id="+yjy_whole_info_id+"&materialnum="+materialnum;
    http.post(url, {}, true).then((s) => {
      this.dataList = s;
      this.wholeCostVo = this.dataList[0];
    });
  },
  destroyed() {

  },
};


</script>